package com.atguigu.springcloud.exception.capture;

import com.atguigu.springcloud.controller.PaymentController;
import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.exception.PaymentCreateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
@ControllerAdvice(basePackageClasses = PaymentController.class)
public class PaymentExceptionCapture {

    @ExceptionHandler(PaymentCreateException.class)
    public CommonResult createHandle(PaymentCreateException e) {
        log.debug("payment创建异常");
        return new CommonResult(444, "服务器开小差了");
    }

    @ExceptionHandler(Exception.class )
    public CommonResult masterHandle(Exception e) {
        log.debug("payment操作异常:[{}]",e.getLocalizedMessage());
        return new CommonResult(900, "服务器异常，请联系管理员");
    }
}
